package net.pimpas.web.jsf.components.validators.regex.custom;

import javax.faces.context.FacesContext;

import net.pimpas.web.jsf.components.validators.regex.Regex;
import net.pimpas.web.jsf.components.validators.regex.RegexValidator;

public class CustomRegexValidator extends RegexValidator {
	
	private Regex regex;
	
	public static final String MESSAGE_KEY			= RegexValidator.REGEX_KEY_MESSAGE+".custom";
	public static final String VALIDATOR_ID			= RegexValidator.VALIDATOR_ID+".custom";
	
	@Override
	public Object saveState(FacesContext context) {
		Object[] ob = new Object[2];
		ob[0] = super.saveState(context);
		ob[1] = this.getRegex();
		
		return ob;
	}
	
	@Override
	public void restoreState(FacesContext context, Object state) {
		Object[] ob = (Object[]) state;
		super.restoreState(context, ob[0]);
		this.setRegex((Regex) ob[1]);
	}

	@Override
	public String getMessageKey() {
		return MESSAGE_KEY;
	}

	@Override
	public Regex getRegex() {
		return this.regex;
	}

	public void setRegex(Regex regex) {
		this.regex = regex;
	}
}